<?php

/**
 * @author Mr Tuan - richdad.tx@gmail.com
 * @copyright 2012
 */

class MtFptController extends CController{
    
    public function actions()
    {
       return array(
        'FeedBack' => array(
          'class' => 'CWebServiceAction',
        ),
      );
    }
    
        /**
     * @param integer $MOId  
     * @param string $Telco 
     * @param string $Phone 
     * @param string $ServiceNum
     * @param string $Syntax
     * @param integer $MessageCode 
     * @param string $EncryptMessage
     * @param string $PartnerCode
     * @param string $Signature
     * @param datetime $DateSend
     * @param float $IsSendNow
     * @return string
     * @soap
     */
    
    function Send($MOId ,$Telco,$Phone,$ServiceNum,$Syntax,$MessageCode ,$EncryptMessage,$PartnerCode ,$Signature,$DateSend,$IsSendNow){
        	// init param for example
        	$MOId 		 = 123456;
        	$Telco		 = 'viettel';
        	$Phone		 = '84972440603';
        	$ServiceNum	 = '8100';
        	$Syntax		 = 'abc';
        	$MessageCode = 0;
        	$Message	 = 'Noi dung tin MT thu 2.';
        	$PartnerCode = 'aaaaaaaaaaaaaaaa';
        	$DateSend	 = date('Y-m-d\TH:i:s');
        	$IsSendNow	 = true;	
        	
        	// begin digital sign
            $OriginalData  = $PartnerCode.$Message.$Phone;
        	
            $private_key = "key/SMS.pem";
            $private_key_pass = "smsgatevn";
            
            if (openssl_sign($OriginalData, $Signature, array(file_get_contents($private_key), $private_key_pass)))
            {   
        		$Signature = base64_encode($Signature);
            }
        	
        	// begin convert to Base64
        	$EncryptMessage = base64_encode($Message);
        
           /* // Call method
        	$result = $client->call('Send', array(
        		  'MOId' 			=> $MOId
        		, 'Telco' 			=> $Telco
        		, 'Phone' 			=> $Phone
        		, 'ServiceNum' 		=> $ServiceNum
        		, 'Syntax' 			=> $Syntax
        		, 'MessageCode'		=> $MessageCode
        		, 'EncryptMessage' 	=> $EncryptMessage
        		, 'PartnerCode' 	=> $PartnerCode
        		, 'Signature' 		=> $Signature
        		, 'DateSend' 		=> $DateSend
        		, 'IsSendNow'		=> $IsSendNow
        	));
        
            // fault if any
            if ($client->fault) {
                echo '<h2>Fault</h2><pre>';
                print_r($result);
                echo '</pre>';
            } else {       
                // Check for errors
                $err = $client->getError();       
                if ($err) {       
                    // Display the error
                    echo '<h2>Error</h2><pre>' . $err . '</pre>';       
                } else {       
                    // Display the result
                    echo '<h2>Result</h2><pre>';        
        			//echo "factorial for 5 = ".$result['factorialResult'];
        			echo 'Call "Send" response = '.$result['SendResult'];       
                    echo '</pre>';       
                }       
            }*/
    }
    public function actionFeed(){
        ini_set('display_errors','on');
        $wsdl = 'http://canhsong.com/Index.php/serviceFpt/MOReceive';
        $client = new SoapClient($wsdl);
        echo $client->Send("84986812496","8041","0","CS","CS TEST","canhsong","123456","","","");
        exit ;
    }
}


?>